<template>
  <el-container>
    <el-header>
      <div>
        <img src="../assets/prcture1.jpg" alt="">
        <span>电商后台管理</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="iscollapse ? '64px':'200px'">
        <div class="toggle-button" @click="fold()">lll</div>
        <el-menu background-color="#333744" text-color="#fff" active-text-color="#409eff" :unique-opened="true" :collapse="iscollapse" :collapse-transition='false' router :default-active="isHigh">
          <!-- 一级菜单 -->
          <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
            <template slot="title">
              <!-- 菜单图标 -->
              <i :class="iconObj[item.id]"></i>
              <!-- 菜单名称 -->
              <span>{{item.authName}}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item :index="'/'+subitem.path" v-for="subitem in item.children" :key="subitem.id" @click="saveStatus('/'+subitem.path)">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{subitem.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>

</template>

<script>
export default {
  data: function () {
    return {
      menulist: [],
      iconObj: {
        125: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      },
      iscollapse: false,
      isHigh: ''
    }
  },
  created () {
    this.getMenuList()
    this.isHigh = window.sessionStorage.getItem('status')
  },
  methods: {
    logout () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async getMenuList () {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.menulist = res.data
    },
    fold () {
      this.iscollapse = !this.iscollapse
    },
    saveStatus (status) {
      window.sessionStorage.setItem('status', status)
      this.isHigh = status
    }
  }
}
</script>
<style lang="less" scoped>
.el-container{
  height: 100%;
}
.el-header{
  height: 90px!important;
  background-color: #373d41;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  >div{
    height: 90px;
    display: flex;
    flex-direction: row;
    align-items: center;
    font-size: 26px;
    color: #ffffff;
    img{
       width:90px;
       border-radius: 100%;
    }
    span{
      padding-left: 30px;
    }
  }
}
.el-aside{
  background-color: #333744;
  .el-menu{
    border: none;
  }
}
.el-main{
  background-color: #eaedf1;
}
.iconfont{
  margin-right: 10px;
}
.toggle-button{
  background-color: #4a5064;
  height: 24px;
  line-height: 24px;
  text-align: center;
  color: #ffffff;
  letter-spacing:0.2em;
  font-size: 20px;
  padding: 2px 0px;
  cursor: pointer;
}
</style>
